package cn.smxy.admin.controller;


import cn.smxy.admin.aop.log.Log;
import cn.smxy.admin.service.UserService;
import cn.smxy.param.CampusRemoveParam;
import cn.smxy.param.CampusSearchParam;
import cn.smxy.param.PageParam;
import cn.smxy.param.UserSearchParam;
import cn.smxy.pojo.Campus;
import cn.smxy.pojo.User;
import cn.smxy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/save/excel")
    public R saveExcel(@RequestPart("file")MultipartFile file) throws IOException {
        return userService.saveExcel(file);
    }

    /**
     * 返回用户基本信息接口
     *
     * @param userId 用户id
     * @return
     */
    @GetMapping("/basic/{userId}")
    public User basic(@PathVariable Long userId){
        return userService.basic(userId);
    }


    /**
     * 分页展示用户接口
     *
     * @param pageParam
     * @return
     */
    @GetMapping("/page")
    @Log(name = "分页展示用户")
    public R page(PageParam pageParam){
        return userService.page(pageParam);
    }

    /**
     * 修改用户信息接口
     *
     * @param user
     * @return
     */
    @PostMapping("/update")
    @Log(name = "修改用户信息")
    public R update(User user){
        return userService.update(user);
    }

    /**
     * 删除用户接口
     *
     * @param userId
     * @return
     */
    @PostMapping("/delete/{userId}")
    @Log(name = "删除用户")
    public R delete(@PathVariable Long userId){
        return userService.delete(userId);
    }

    /**
     * 添加用户接口
     *
     * @param user
     * @return
     */
    @PostMapping("/save")
    @Log(name = "添加用户")
    public R save(User user){
        return userService.save(user);
    }

    /**
     * 图片上传接口
     * @param img
     * @return
     * @throws Exception
     */
    @PostMapping("/upload")
    public Object upload(@RequestPart("img") MultipartFile img) throws Exception {
        return userService.upload(img);
    }

    /**
     * 模糊分页查询用户名接口
     * @param userSearchParam
     * @return
     */
    @GetMapping("/search")
    @Log(name = "模糊分页查询用户名")
    public R search(UserSearchParam userSearchParam){
        return userService.search(userSearchParam);
    }

    /**
     * excel批量导出接口
     * @param response
     */
    @GetMapping("/export")
    public void export(HttpServletResponse response) throws IOException{
        userService.export(response);
    }

    /**
     * 分页展示校园认证接口
     * @param campusSearchParam
     * @return
     */
    @GetMapping("/campus/page")
    public R campusPage(CampusSearchParam campusSearchParam) {
        return userService.campusPage(campusSearchParam);
    }

    /**
     * 校园学生认证接口
     * @param campus
     * @return
     */
    @PostMapping("/campus/check")
    public R check(Campus campus){
        return userService.check(campus);
    }

    /**
     * 校园认证批量删除接口
     *
     * @param campusRemoveParam
     * @return
     */
    @PostMapping("/campus/remove/batch")
    public R campusRemoveBatch(CampusRemoveParam campusRemoveParam) {
        return userService.campusRemoveBatch(campusRemoveParam);
    }
}
